package com.application.moneycalculator.activity;

import com.application.moneycalculator.R;
import com.application.moneycalculator.log.Log_;
import com.application.moneycalculator.settings.Settings;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;

public class IntroductionActivity extends BaseActivity {
	
	private final String TAG = "IntroductionActivity";
	
	private Button nextActivityButton;
	private Button exitActivityButton;
	
	private CheckBox checkBoxSkip;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Log_.out(TAG, "onCreate start");
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.introduction);
        
        nextActivityButton = (Button) findViewById(R.id.button_next_introduction);
        nextActivityButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Log_.out(TAG, "try to show next Activity");
				showNextActivity();
			}
		});
        
        exitActivityButton = (Button) findViewById(R.id.button_exit_introduction);
        exitActivityButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Log_.out(TAG, "Kill application");
				//System.exit(0);
				//IntroductionActivity.this.finish();
				android.os.Process.killProcess(android.os.Process.myPid());
			}
		});
        
        checkBoxSkip = (CheckBox) findViewById(R.id.checkBox_skip_introduction);
        checkBoxSkip.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Log_.out(TAG, "Check box presssed");
				Settings.setSkipIntroduction(IntroductionActivity.this, IntroductionActivity.this.checkBoxSkip.isChecked());
			}
		});
        
		try {
			boolean skipSetting = Settings.getSkipIntroduction(this);
			checkBoxSkip.setChecked(skipSetting);
			if(skipSetting)
			{
				showNextActivity();
				finish();
			}
		} catch (Exception e) {
			Log_.out(TAG, "!!!!!!!!!!!!!");
			e.printStackTrace();
		}
		
		TestThread testThread = new TestThread(this);
		testThread.start();
        
        
        Log_.out(TAG, "onCreate finish");
    }
    
    private void showNextActivity()
    {
    	Intent intent = new Intent(IntroductionActivity.this, AllExpensesActivity.class);
		startActivity(intent);
    }
    
}